import pygame
import random
import math

# 初始化 Pygame
pygame.init()

# 设置屏幕尺寸和标题
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("unicorn")

# 定义颜色
red = (255, 0, 0)
black = (0, 0, 0)

# 粒子类
class Particle:
    def __init__(self, x, y, target_x, target_y):
        self.x = x
        self.y = y
        self.target_x = target_x
        self.target_y = target_y
        self.vx = random.uniform(-2, 2)
        self.vy = random.uniform(-2, 2)
        self.size = random.randint(2, 5)
        self.color = (random.randint(200, 255), 0, 0)

    def update(self):
        dx = self.target_x - self.x
        dy = self.target_y - self.y
        dist = math.sqrt(dx ** 2 + dy ** 2)
        if dist > 1:
            self.vx += dx * 0.01
            self.vy += dy * 0.01
        self.x += self.vx
        self.y += self.vy
        self.vx *= 0.95
        self.vy *= 0.95

        # 让粒子闪烁
        self.color = (random.randint(200, 255), 0, 0)

    def draw(self, screen):
        pygame.draw.circle(screen, self.color, (int(self.x), int(self.y)), self.size)

# 生成爱心形状的粒子
particles = []
for t in range(1000):
    angle = t * 0.1
    x = 16 * math.sin(angle) ** 3
    y = 13 * math.cos(angle) - 5 * math.cos(2 * angle) - 2 * math.cos(3 * angle) - math.cos(4 * angle)
    x = x * 20 + width // 2
    y = -y * 20 + height // 2
    particles.append(Particle(random.uniform(0, width), random.uniform(0, height), x, y))

# 主循环
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.fill(black)

    for particle in particles:
        particle.update()
        particle.draw(screen)

    pygame.display.flip()
    pygame.time.delay(10)

pygame.quit()
